package com.dream.keigezhushou.Activity.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.dream.keigezhushou.Activity.Uiutils.UiUtils;
import com.dream.keigezhushou.Activity.bean.DynamicInfo;
import com.dream.keigezhushou.R;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.ArrayList;

import butterknife.ButterKnife;

public class HotDynamicActivity extends BaseActivity implements View.OnClickListener {


    private PullToRefreshListView mMpullListview;
    private ImageView mMBack;
    private ListView mMlist;
    public ArrayList<DynamicInfo> list = new ArrayList<>();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_dynamic);
        ButterKnife.bind(this);
        initdata();

        mMBack = (ImageView) findViewById(R.id.back);
        mMBack.setOnClickListener(this);
        mMpullListview = (PullToRefreshListView) findViewById(R.id.hotdynamicpulllist);
        mMlist = mMpullListview.getRefreshableView();
        mMlist .setAdapter(new MyAdapter());

    }

    private void initdata() {
        for (int i =0;i<18;i++){
            DynamicInfo info = new DynamicInfo();
            info.setIv(getResources().getDrawable(R.mipmap.dsdd));
            info.setSongname("天黑黑");
            info.setTitle("娃娃");
            info.setType("合唱");
            info.setTime("3分钟前");
            list.add(info);
        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
            break;
        }
    }

class MyAdapter extends BaseAdapter {
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public DynamicInfo getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder =null;
        if(convertView==null){
            convertView = UiUtils.inflateView(R.layout.item_song);
            holder = new ViewHolder();
            holder.iv = (ImageView) convertView.findViewById(R.id.ivcon);
            holder.tv = (TextView) convertView.findViewById(R.id.name);
            holder.time = (TextView) convertView.findViewById(R.id.time);
            holder.play = (ImageView) convertView.findViewById(R.id.bg_icon);
            holder.name = (TextView) convertView.findViewById(R.id.songname);
            holder.type = (TextView) convertView.findViewById(R.id.type);
            holder.share = (TextView) convertView.findViewById(R.id.zf);
            holder.common = (TextView) convertView.findViewById(R.id.common);
            convertView.setTag(holder);

        }else{
            holder = (ViewHolder) convertView.getTag();
        }


        DynamicInfo info = getItem(position);
        holder.iv.setImageDrawable(info.getIv());
        holder.tv.setText(info.getTitle());
        holder.name.setText(info.getSongname());
        holder.time.setText(info.getTime());

        holder.type.setText(info.getType());
        if("合唱".equals(info.getType())){
            holder.type.setTextColor(getResources().getColor(R.color.hebg));
            holder.type.setBackground(getResources().getDrawable(R.mipmap.hebg));
        }else{
            holder.type.setTextColor(getResources().getColor(R.color.zbg));
            holder.type.setBackground(getResources().getDrawable(R.mipmap.zbg));
        }

        holder.common.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                UiUtils.toast("输入评论");
            }
        });

        holder.play.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UiUtils.toast("开始播放");
                //调到页面
            }
        });

        holder.share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                UiUtils.toast("分享");
            }
        });




        return convertView;
    }


}
    static class ViewHolder{
        ImageView iv;
        TextView tv;
        TextView name;
        TextView time;

        TextView type;
        ImageView play;
        TextView common;
        TextView share;

    }
}
